import socket

socket_client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # 通信协议为UDP
server_address = ('127.0.0.1', 8000)  # 保存服务器地址

while True:
    send_msg = input("请输入发给服务端的信息：")
    if send_msg == 'exit':
        break

    socket_client.sendto(send_msg.encode("utf8"), server_address)  # 改为sendto
    recv_msg, addr = socket_client.recvfrom(1024)  # 改为recvfrom
    recv_msg = recv_msg.decode("utf8")
    print(f"服务端回复的信息是：{recv_msg}")

socket_client.close()
